<?php
	/**
	* @File name:	index.php
	* @Desription:	des
	* @Author:	 	jinxin<jx@178.com>   
	* @Date:	 	2012-3-25
	* @Copyright 	Copytright (c) 2008-2012 alucard.jx@gmail.com.
	*/
	
	class admin_login_controller_index extends controller{
		public $o;
		public function __construct($app,$controller,$site){
			parent::__construct($app, $controller, $site);
			$this->o = model::factory('admin_login_model_user','admin');
		}
	
		public function form(){
			$this->rander = 'single';
			$this->attr['to'] = $this->_fget('to','string','');
		}
		
		public function login(){
			$username = $this->_fpost('username','string','');
			$password = $this->_fpost('password','string','');
			$to = $this->_fpost('to','string','');
			if($username == '' || $password == ''){
				return $this->hint('用户名或者密码不能为空!','error',$this->_getUri('login', 'index', 'form',array('to'=>$to)));
			}
			if(!$uInfo = $this->o->getUserByName($username)){
				return $this->hint('该用户不存在!','error',$this->_getUri('login', 'index', 'form',array('to'=>$to)));
			}
			if (md5($password) != $uInfo['password']) {
				return $this->hint('密码错误!','error',$this->_getUri('login', 'index', 'form',array('to'=>$to)));;
			}
			self::$login = array(
				'uid'			=> $uInfo['id'],
			        'username'	=> $uInfo['username']
			);
			$_SESSION['uid'] = $uInfo['id'];
			$_SESSION['username'] = $uInfo['username'];
			$_SESSION['group_id'] = $uInfo['group_id'];
			setcookie('admin_sid',$_SESSION['SID'],time()+3600,'/',$_SERVER['config']['domain']['admin']);
			setcookie('admin_uid',$_SESSION['uid'],time()+3600,'/',$_SERVER['config']['domain']['admin']);
			setcookie('admin_author',$_SESSION['username'],time()+3600,'/',$_SERVER['config']['domain']['admin']);
			setcookie('admin_group_id',$_SESSION['group_id'],time()+3600,'/',$_SERVER['config']['domain']['admin']);
			return $this->hint('登录成功');
			
		}
	}
